package com.qingke.notlonely.command.system;

import com.qingke.notlonely.bean.Yue;
import com.qingke.notlonely.command.SystemCommand;
import com.qingke.notlonely.util.NLConsole;

public class AlterYue extends SystemCommand{

	@Override
	public void execute() {
		int id=NLConsole.getInt("yue id:");
		boolean isExist=dao.isYueExistById(id);
		if(!isExist){
			NLConsole.println("the yue is not exist.");
			return ;
		}
		
		boolean isAccepted;
		while(true){
			String str=NLConsole.promptNotEmpty("new is accepted(y,n):").trim();
			if("y".equalsIgnoreCase(str))
				isAccepted=true;
			else if("n".equalsIgnoreCase(str))
				isAccepted=false;
			else{
				NLConsole.println("err input");
				continue;
			}
			break;
		}
		
		Yue yue=dao.selectYueById(id);
		yue.setAccepted(isAccepted);
		
		boolean isSuccess=dao.update(yue);
		if(isSuccess)
			NLConsole.println("alter yue success.");
		else
			NLConsole.println("alter yue failed.");
	}

}
